<div class='tabs'>
	<div class="uc_title m_10 tabs_menu">
		<label class="current node"><span>修改密码</span></label>
	</div>
</div>
<table class="form_table" width="100%" cellpadding="0" cellspacing="0">
	<col width="120px" />
	<col />
	<tr>
		<th>原密码：</th>
		<td><input id='oldpwd' class="normal" type="text" /><label id="checkpwd"></label></td>
	</tr>
	<tr>
		<th>新密码：</th>
		<td><input id='newpwd' class="normal" type="text" /><label></label></td>
	</tr>
	<tr>
		<th>确认密码：</th>
		<td><input id='cfmpwd' class="normal" type="text" /><label></label></td>
	</tr>
	<tr>
		<th></th>
		<td><label class="btn"><input type="button" id="updatepwd" value="保存" /></label> <label class="btn"><input
					type="button" id="cancel" value="取消" /></label></td>
	</tr>
</table>
<script>
	$(function () {
		// 记录验证通过数
		var list = new Array();
		list[0] = 1;
		list[1] = 1;
		list[2] = 1;


		$("#oldpwd").blur(function () {
			$.ajax({
				type: "post",
				url: "/user",
				data: "opr=check&pwd=" + $("#oldpwd").val(),
				dataType: "json",
				success: function (msg, states, xhr) {
					if (xhr.readyState != 4 || xhr.status != 200) {
						//加载层-风格4
						layer.msg('密码验证中', {
							icon: 16
							, shade: 0.01
						});
					}
					if (msg.msg == 'ok') {
						$("#checkpwd").prop("style").color = "rgb(18, 157, 81)";
						$("#oldpwd").prop("style").backgroundColor = "aquamarine";
						$("#oldpwd").next().text("验证通过");
						list[0] = 0;
					} else {
						$("#checkpwd").prop("style").color = "red";
						$("#oldpwd").prop("style").backgroundColor = "rgb(244, 169, 155)";
						$("#oldpwd").next().text(msg.msg);
						list[0] = 1;
					}
				},
				error: function () {
					layer.msg('系统繁忙，请稍后再试', { icon: 2 });
				}
			})
		});
		$("#newpwd").blur(function () {
			let newpwd = this.value;
			if (newpwd.trim().length < 6 || newpwd.trim().length > 32) {
				$(this).next().text("密码长度6-32个字符");
				$(this).next().prop("style").color = "red";
				$(this).prop("style").backgroundColor = "rgb(244, 169, 155)";
				list[1] = 1;
			} else {
				$(this).next().text("验证通过");
				$(this).next().prop("style").color = "rgb(18, 157, 81)";
				$(this).prop("style").backgroundColor = "aquamarine";
				list[1] = 0;
			}
		});
		$("#cfmpwd").blur(function () {
			let newpwd = $("#newpwd").val();
			let cfmpwd = this.value;
			if (newpwd != cfmpwd) {
				$(this).next().text("两次密码不一致");
				$(this).next().prop("style").color = "red";
				$(this).prop("style").backgroundColor = "rgb(244, 169, 155)";
				list[2] = 1;

			} else {
				$(this).next().text("密码一致");
				$(this).next().prop("style").color = "rgb(18, 157, 81)";
				$(this).prop("style").backgroundColor = "aquamarine";
				list[2] = 0;
			}
		});
		$("#updatepwd").click(function () {
			let count = 0;
			for (const i of list) {
				if (i == 0) {
					count++;
				}
			}
			if (count == 3) {
				$.ajax({
					type: "post",
					url: "/user",
					data: "opr=update&pwd=" + $("#newpwd").val() + "&type=1",
					dataType: "json",
					beforeSend: function (r) {
						//加载层-默认风格
						layer.load();
					},
					success: function (msg, states, xhr) {
						if (msg.msg == 'ok') {
							layer.msg('密码修改成功', { icon: 1 });
						} else {
							layer.msg(msg.msg, { icon: 2 });
						}
					},
					complete: function (XMLHttpRequest, textStatus) {
						// alert('远程调用成功，状态文本值：'+textStatus);
						layer.closeAll('loading');
					},
					error: function () {
						layer.msg('系统繁忙，请稍后再试', { icon: 2 });
					}
				})

			} else {
				layer.msg('验证未通过', function () {
					//关闭后的操作
				});
			}

		})
	})
</script>